<template>
    <div>
        <h2>门店录入</h2>
        <table class="table table-bordered">
<tr>
    <td align="right">门店名称</td>
    <td><input type="text" v-model="state.dName" /></td>
</tr>
<tr>
    <td align="right">门店位置</td>
    <td><input type="text" v-model="state.address" /></td>
</tr>

<tr>
    <td align="right">联系方式</td>
    <td><input type="text" v-model="state.phone" /></td>
</tr>
<tr>
    <td align="right">介绍</td>
    <td><input type="text" v-model="state.rimate" /></td>
</tr>
<tr>
    <td align="right"></td>
    <td><input type="button" value="登录" @click="add" /></td>
</tr>
</table>
    </div>
</template>

<script setup lang="ts">
import { reactive,toRefs } from 'vue';
import { useRouter,useRoute } from 'vue-router';
import axios from 'axios';
const router=useRouter();
let data=reactive({
    state:{
        dName:'',
        address:'',
        phone:'',
        rimate:'',
    }
})

let{state}=toRefs(data)

const add=()=>{

if(state.value.dName==""){
    alert("门店名称不能为空")
    return;
}
if(state.value.address==""){
    alert("位置不能为空")
    return;
}
    let obj={
        id: 0,
  dName: state.value.dName,
  address: state.value.address,
  phone: state.value.phone,
  photo: "/imge/4.jpg",
  state: 0,
  rimate: state.value.rimate,
  isDelete: false
    }
    axios({
        url:'/api/Discont/AddDiscont',
        method:'post',
        data:obj
    })
    .then(res=>{
        console.log(res)
        if(res.data==1){
            alert("录入成功")
            router.push("/Dislist")
        }
        else{
            alert("录入失败")
            return;
        }
    })
    .catch(err=>{
        console.log(err)
    })
}



</script>

<style scoped>

</style>